package com.qf.news.service.impl;

import com.qf.news.domain.Luoyanguser;
import com.qf.news.mapper.LuoyanguserMapper;
import com.qf.news.service.LuoyanguserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;


@Service
@Transactional(rollbackFor = Exception.class)
public class LuoyanguserServiceImpl implements LuoyanguserService {
    @Autowired
    LuoyanguserMapper luoyanguserMapper;


    @Override
    public Luoyanguser luoyanguserLogin(String username, String password) {

        List<Luoyanguser> luoyangusers = luoyanguserMapper.selectByName(username);
        for (Luoyanguser luoyanguser : luoyangusers) {
            if (Objects.equals(password, luoyanguser.getPassword())) {
                return luoyanguser;
            }
        }
        return null;
    }

    @Override
    public int  addLuoyanguser(Luoyanguser luoyanguser) {

        return  luoyanguserMapper.insertSelective(luoyanguser);
    }

    @Override
    public int deletenews(Luoyanguser luoyanguser) {
        return luoyanguserMapper.deleteByName(luoyanguser);
    }
}
